package com.tgu.controller;

import com.tgu.entity.request.TrolleyReq;
import com.tgu.entity.request.TrolleyPayReq;
import com.tgu.entity.request.UserCancelReq;
import com.tgu.service.ITrolleyService;
import com.tgu.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("portal/trolley")
public class TrolleyController {

    @Autowired
    private ITrolleyService trolleyService;

    @GetMapping("/myTrolley/{userId}")
    public Result getMyTrolley(@PathVariable String userId) {
        return trolleyService.getTrolleyById(userId);
    }

    @PostMapping("/postTrolley")
    public Result postTrolley(@RequestBody TrolleyReq trolleyReq) {
        return trolleyService.saveTrolley(trolleyReq);
    }

    @PostMapping("/delete")
    public Result deleteById(@RequestBody UserCancelReq deleteReq) {
        return trolleyService.deleteTrolleyById(deleteReq);
    }

    @PostMapping("/pay")
    public Result payByUser(@RequestBody TrolleyPayReq payReq) {
        return trolleyService.payByUserId(payReq);
    }
}
